﻿using BW.EatRabbit.API.Application.Commands.DeeprocessingCompany;
using BW.EatRabbit.Domain;
using BW.EatRabbit.ErrorCode;
using BW.EatRabbit.Infrastructure.Interfaces;
using MediatR;

namespace BW.EatRabbit.API.Application.CommandHandlers.DeeprocessingCompany
{
    public class GetDeeprocessCompanyCommandHandler : IRequestHandler<GetDeeprocessCompanyCommand, APIResult<DeepProcessing_Company>>
    {
        private readonly IBaseRepository<DeepProcessing_Company> _companyRepository;
        public GetDeeprocessCompanyCommandHandler(IBaseRepository<DeepProcessing_Company> companyRepository)
        {
            _companyRepository = companyRepository;
        }
        public Task<APIResult<DeepProcessing_Company>> Handle(GetDeeprocessCompanyCommand request, CancellationToken cancellationToken)
        {
            APIResult<DeepProcessing_Company> result = new APIResult<DeepProcessing_Company>();



            var list = _companyRepository.GetAll().FirstOrDefault(x => x.ProductionBatch == request.ProductionBatch);
            if (list == null)
            {
                result.Code = ResultCode.查询失败;
                result.Message = ResultCode.查询失败.ToString();

            }
            else
            {
                result.Code = ResultCode.查询成功;
                result.Message = ResultCode.查询成功.ToString();
                result.Data = list;
            }
            return Task.FromResult(result);
        }
    }
}
